<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

class CreateAdminMenusTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('admin_menus')) {
            Schema::create('admin_menus', function (Blueprint $table) {
                $table->id();
                $table->string('name')->comment('菜单名');
                $table->string('icon')->nullable()->comment('icon');
                $table->string('path')->nullable()->comment('网络路径');
                $table->string('router')->nullable()->comment('数据API路由');
                $table->integer('parent_id')->default(0)->comment('上级ID');
                $table->integer('order')->default(0)->comment('排序,建议升序排序');
                $table->string('component')->default('layout')->comment('component');
                $table->enum('cache', ['y', 'n'])->default('y')->comment('前端是否被 <keep-alive> 缓存');
                $table->enum('hidden', ['y', 'n'])->default('n')->comment('当设置 y 了后,前端菜单栏不显示');
                $table->string('redirect')->nullable()->comment('重定向');
                $table->enum('always_show', ['y', 'n'])->default('y')->comment('可以设置 always_show: y，一直显示根路由');
                $table->enum('breadcrumb', ['y', 'n'])->default('y')->comment('设置为 n 后,不在面包屑显示');
                $table->enum('affix', ['y', 'n'])->default('n')->comment('如果设置为y，它则会固定在tags-view中(默认 n)');
                $table->string('active_menu')->comment('当路由设置了该属性，则会高亮相对应的侧边栏。这在某些场景非常有用，比如：一个文章的列表页路由为：/article/list, 点击文章进入文章详情页，这时候路由为/article/1，但你想在侧边栏高亮文章列表的路由，就可以进行如下设置');
                $table->enum('is_operate', ['y', 'n'])->default('n')->comment('是否有可操作权限(除了list/show外的权限)');
                $table->softDeletes();
                $table->timestamps();
            });
            DB::statement("ALTER TABLE `admin_menus` comment '菜单表'");
        }
        
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin_menus');
    }
}
